package com.demo.controller;


import com.demo.config.JwtTemplate;
import com.demo.controller.from.ostentationListAddFrom;
import com.demo.exetion.MainExection;
import com.demo.model.MovieNumberSession;
import com.demo.service.MovieNumberSessionService;
import com.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2022-04-05
 */
@RestController
@RequestMapping("/movieNumberSession")
@Api(value = "场次",tags = "场次")
public class MovieNumberSessionController {

    @Resource
    private MovieNumberSessionService movieNumberSessionService;
    @PostMapping("/ostentation")
    @ApiOperation(value = "排场",notes = "排场")
    @ApiImplicitParam(value = "鉴权token",name = "authentication_token",paramType  = "header", dataType = "String", required=true)
    public Result<List<MovieNumberSession>> ostentation(@RequestBody ostentationListAddFrom ostentationListAddFrom, BindingResult bindingResult) throws MainExection {
        System.out.println(ostentationListAddFrom);
        if (bindingResult.hasErrors()) {
            throw new MainExection(500, "参数校验未通过");
        }
        List<MovieNumberSession> ostentation = movieNumberSessionService.ostentation(ostentationListAddFrom);
        return Result.getInstanceList(MovieNumberSession.class).setData(ostentation);
    }

    @GetMapping("/login")
    @ApiOperation(value = "获取token",notes = "获取token")
    public Result<String> login() throws MainExection {
        JwtTemplate jwtTemplate=new JwtTemplate();
        Map<String,Object> maps=new HashMap<>();
        maps.put("id",1);
        maps.put("name","admin");
        String jwt = jwtTemplate.createJwt(3,maps);
        return Result.getInstance(String.class).setData(jwt);
    }

}

